package com.wang.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Classname BindController
 * @Description TODO
 * @Date 2024/5/21 9:32
 * @Created by pc
 */
@Slf4j
@RestController
public class BindController {
    @InitBinder
    public void initBinder(WebDataBinder webDataBinder){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor customDateEditor = new CustomDateEditor(df, true);
        webDataBinder.registerCustomEditor(Date.class,customDateEditor);
    }


    @RequestMapping("/bind")
    public Map<String,Object> getFormatDate(Date date){
        Map<String,Object> map = new HashMap<>();
        map.put("name","111");
        map.put("date",date);
        return map;
    }
}
